package com.whalehearing.tingyou.web.controller.hearing;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.domain.HearingImg;
import com.whalehearing.tingyou.service.IHearingImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 听力图Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-13
 */
@Api(tags = "听力图管理")
@RestController
@DataSource(DataSourceType.SLAVE)
@RequestMapping("system/tingyou/hearingImg")
public class HearingImgController extends BaseController {
    @Autowired
    private IHearingImgService hearingImgService;

    /**
     * 查询听力图列表
     */
    @ApiOperation("查询听力图列表")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingImg hearingImg) {
        startPage();
        List<HearingImg> list = hearingImgService.selectHearingImgList(hearingImg);
        return getDataTable(list);
    }

    /**
     * 导出听力图列表
     */
    @ApiOperation("导出听力图列表")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:export')")
    @Log(title = "听力图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingImg hearingImg) {
        List<HearingImg> list = hearingImgService.selectHearingImgList(hearingImg);
        ExcelUtil<HearingImg> util = new ExcelUtil<HearingImg>(HearingImg.class);
        util.exportExcel(response, list, "听力图数据");
    }

    /**
     * 获取听力图详细信息
     */
    @ApiOperation("获取听力图详细信息")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:query')")
    @GetMapping(value = "/{hearingImgId}")
    public AjaxResult getInfo(@PathVariable("hearingImgId") Long hearingImgId) {
        return success(hearingImgService.getById(hearingImgId));
    }

    /**
     * 新增听力图
     */
    @ApiOperation("新增听力图")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:add')")
    @Log(title = "听力图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingImg hearingImg) {
        return toAjax(hearingImgService.save(hearingImg));
    }

    /**
     * 修改听力图
     */
    @ApiOperation("修改听力图")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:edit')")
    @Log(title = "听力图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingImg hearingImg) {
        return toAjax(hearingImgService.updateById(hearingImg));
    }

    /**
     * 删除听力图
     */
    @ApiOperation("删除听力图")
    @PreAuthorize("@ss.hasPermi('tingyou:hearingImg:remove')")
    @Log(title = "听力图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hearingImgIds}")
    public AjaxResult remove(@PathVariable Long[] hearingImgIds) {
        return toAjax(hearingImgService.removeByIds(Arrays.asList(hearingImgIds)));
    }
}
